﻿using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Profiles;

namespace Konekcija.Core.Reporting.Mappings.Profiles
{
    public class MobileDeviceMap : ClassMap<MobileDevice>
    {
        public MobileDeviceMap()
        {
            Schema("profile");
            Table("MobileDevices");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            Map(x => x.DeviceKey).Nullable();
            Map(x => x.Os).Nullable();
            Map(x => x.OsVersion).Nullable();           
            Map(x => x.Allow).Nullable();
            Map(x => x.DateCreated).Nullable();

            References(x => x.CommunicationChannel);
            References(x => x.DeveloperApiPermission).Nullable();

            HasMany(x => x.MobileDeviceTokens)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("MobileDeviceId")
                .Where("Active = 1");

        }
    }
}
